/*
 * File name:  PMIPActivit.java
 * Copyright:  Copyright (c) 2006-2013 hoperun Inc,  All rights reserved
 * Description:  <描述>
 * Author:  ren_qiujing
 * Last modified date:  2013-9-12
 * Version:  <版本编号>
 * Edit history:  <修改内容><修改人>
 */
package com.hoperun.checkcloth.base;

import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.hoperun.checkcloth.view.WaitDialog;


/**
 *
 */
public abstract class MIP_BaseActivity extends AppCompatActivity {
    private WaitDialog mWaitDialog;

    protected String TAG = "";
    private Handler mHandler = new Handler();

    public boolean isActivityDestroyed() {
        return isActivityDestroyed;
    }

    public void setActivityDestroyed(boolean isActivityDestroyed) {
        this.isActivityDestroyed = isActivityDestroyed;
    }

    protected boolean isActivityDestroyed = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        TAG = this.getClass().getName();
        // 设置界面无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置界面常亮
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
                WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        mWaitDialog = new WaitDialog(this);
        super.onCreate(savedInstanceState);

    }

    /**
     * 显示加载圈圈...
     */
    public void showWait() {
        mWaitDialog.show();
    }

    /**
     * 停掉加载圈圈...
     */
    public void stopWait() {
        mWaitDialog.dismiss();
    }

    public void toast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    protected void onDestroy() {
        isActivityDestroyed = true;
        super.onDestroy();
    }

    protected Handler mMIPHandler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            int requestType = msg.what;
            int errorCode = msg.arg1;
            Object retObj = msg.obj;
            try {
                if (errorCode == 0) {

                    onPostHandle(requestType, retObj, true);

                } else {
                    onPostHandle(requestType, retObj, false);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            super.handleMessage(msg);
        }

    };

    abstract public void onPostHandle(int requestType, Object objBody, boolean error) throws Exception;

}
